/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) 
    {
        if((head == NULL) || (head -> next == NULL))
            return head;
        
        ListNode* p = head;
        ListNode* pNext = p -> next;

        while(pNext)
        {
            if(p -> val == pNext -> val)
            {
                p -> next = pNext -> next;
                delete pNext;
                pNext = p -> next;
            }
            else
            {
                p = pNext;
                pNext = pNext -> next;
            }
        }

        return head;
    }
};